package concurrent;

/**
 * @Author: huangkunming
 * @Date: 2023/7/18 19:02
 * @Description:
 * 查看字节码信息
 * 1、执行javac编译成.class文件
 * 2、进入target目录下找到对应的.class文件
 * 3、执行javap -c -s -v -l .\SynchronizedMethodDemo.class
 */
public class SynchronizedMethodDemo {

    public synchronized void method() {
        System.out.println("test method");
    }
}

/*
* 同步方法使用的是class锁，字节码信息中，并没有使用monitorenter和monitorexit
* 使用ACC_SYNCHRONIZED标记：JVM通过该访问标记来辨别一个方法是否声明为同步方法。
* */

/**
 * PS D:\personal_workspace\study_notes\test\target\classes\concurrent> javap -c -s -v -l .\SynchronizedMethodDemo.class
 * Classfile /D:/personal_workspace/study_notes/test/target/classes/concurrent/SynchronizedMethodDemo.class
 *   Last modified 2023-7-18; size 539 bytes
 *   MD5 checksum 37f92d2efd51e61bd8065046ee0d5f45
 *   Compiled from "SynchronizedMethodDemo.java"
 * public class concurrent.SynchronizedMethodDemo
 *   minor version: 0
 *   major version: 52
 *   flags: ACC_PUBLIC, ACC_SUPER
 * Constant pool:
 *    #1 = Methodref          #6.#17         // java/lang/Object."<init>":()V
 *    #2 = Fieldref           #18.#19        // java/lang/System.out:Ljava/io/PrintStream;
 *    #3 = String             #20            // test method
 *    #4 = Methodref          #21.#22        // java/io/PrintStream.println:(Ljava/lang/String;)V
 *    #5 = Class              #23            // concurrent/SynchronizedMethodDemo
 *    #6 = Class              #24            // java/lang/Object
 *    #7 = Utf8               <init>
 *    #8 = Utf8               ()V
 *    #9 = Utf8               Code
 *   #10 = Utf8               LineNumberTable
 *   #11 = Utf8               LocalVariableTable
 *   #12 = Utf8               this
 *   #13 = Utf8               Lconcurrent/SynchronizedMethodDemo;
 *   #14 = Utf8               method
 *   #15 = Utf8               SourceFile
 *   #16 = Utf8               SynchronizedMethodDemo.java
 *   #17 = NameAndType        #7:#8          // "<init>":()V
 *   #18 = Class              #25            // java/lang/System
 *   #19 = NameAndType        #26:#27        // out:Ljava/io/PrintStream;
 *   #20 = Utf8               test method
 *   #21 = Class              #28            // java/io/PrintStream
 *   #22 = NameAndType        #29:#30        // println:(Ljava/lang/String;)V
 *   #23 = Utf8               concurrent/SynchronizedMethodDemo
 *   #24 = Utf8               java/lang/Object
 *   #25 = Utf8               java/lang/System
 *   #26 = Utf8               out
 *   #27 = Utf8               Ljava/io/PrintStream;
 *   #28 = Utf8               java/io/PrintStream
 *   #29 = Utf8               println
 *   #30 = Utf8               (Ljava/lang/String;)V
 * {
 *   public concurrent.SynchronizedMethodDemo();
 *     descriptor: ()V
 *     flags: ACC_PUBLIC
 *     Code:
 *       stack=1, locals=1, args_size=1
 *          0: aload_0
 *          1: invokespecial #1                  // Method java/lang/Object."<init>":()V
 *          4: return
 *       LineNumberTable:
 *         line 12: 0
 *       LocalVariableTable:
 *         Start  Length  Slot  Name   Signature
 *             0       5     0  this   Lconcurrent/SynchronizedMethodDemo;
 *
 *   public synchronized void method();
 *     descriptor: ()V
 *     flags: ACC_PUBLIC, ACC_SYNCHRONIZED
 *     Code:
 *       stack=2, locals=1, args_size=1
 *          0: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
 *          3: ldc           #3                  // String test method
 *          5: invokevirtual #4                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
 *          8: return
 *       LineNumberTable:
 *         line 15: 0
 *         line 16: 8
 *       LocalVariableTable:
 *         Start  Length  Slot  Name   Signature
 *             0       9     0  this   Lconcurrent/SynchronizedMethodDemo;
 * }
 * SourceFile: "SynchronizedMethodDemo.java"
 *
 * */


